﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TableParsers;

namespace SpeakupTests.WebLayer.ClassTypes
{
    [TestClass]
    public class ClassTimeParserTests
    {
        class ClassTimeContainer
        {
            public ClassTimeContainer(String date, String begin, String end)
            {
                Date = date;
                Begin = begin;
                End = end;
            }

            public String Date;
            public String Begin;
            public String End;
        }

        [TestMethod]
        public void AttendedOrMissedClassTimeParser()
        {
            List<ClassTimeContainer> txtClassTimes = new List<ClassTimeContainer>();
            List<ClassTime> classTimes = new List<ClassTime>();

            txtClassTimes.Add(new ClassTimeContainer("10-03-02", 
                                                     "18:30:00", "19:30:00"));
            classTimes.Add( new ClassTime(new DateTime(2010, 3, 2), 
                                          new TimeSpan(18, 30, 00), new TimeSpan(19, 30, 0)) );

            txtClassTimes.Add(new ClassTimeContainer("09-11-19",
                                                     "17:00:00", "17:30:00"));
            classTimes.Add(new ClassTime(new DateTime(2009, 11, 19),
                                          new TimeSpan(17, 00, 00), new TimeSpan(17, 30, 0)));

            txtClassTimes.Add(new ClassTimeContainer("09-10-26",
                                                     "19:00:00", "20:00:00"));
            classTimes.Add(new ClassTime(new DateTime(2009, 10, 26),
                                          new TimeSpan(19, 00, 00), new TimeSpan(20, 00, 0)));


            Assert.AreEqual(txtClassTimes.Count, classTimes.Count);
            for (int i = 0; i < txtClassTimes.Count; i++)
            {
                ClassTime parsed =
                    ClassTimeParser.ParseAttendedEntry(txtClassTimes[i].Date,
                                                       txtClassTimes[i].Begin,
                                                       txtClassTimes[i].End);

                Assert.AreEqual(classTimes[i], parsed);                                
            }
                     
        }

        [TestMethod]
        public void CancelledClassTimeParser()
        {
            List<ClassTimeContainer> txtClassTimes = new List<ClassTimeContainer>();
            List<ClassTime> classTimes = new List<ClassTime>();

            txtClassTimes.Add(new ClassTimeContainer("Oct 20 2009 12:00:00:000AM",
                                                     "08:30", "09:30"));
            classTimes.Add(new ClassTime(new DateTime(2009, 10, 20),
                                          new TimeSpan(8, 30, 00), new TimeSpan(9, 30, 0)));


            Assert.AreEqual(txtClassTimes.Count, classTimes.Count);
            for (int i = 0; i < txtClassTimes.Count; i++)
            {
                ClassTime parsed =
                    ClassTimeParser.ParseCancelledEntry(txtClassTimes[i].Date,
                                                        txtClassTimes[i].Begin,
                                                        txtClassTimes[i].End);

                Assert.AreEqual(classTimes[i], parsed);
            }
        }

        [TestMethod]
        public void ReservedClassTimeParser()
        {
            List<String> txtClassTimes = new List<String>();
            List<ClassTime> classTimes = new List<ClassTime>();
            
            txtClassTimes.Add("Saturday 17/07/2010 13:30 - 14:30");            
            classTimes.Add(new ClassTime(new DateTime(2010, 7, 17),
                                          new TimeSpan(13, 30, 00), new TimeSpan(14, 30, 0)));

            Assert.AreEqual(txtClassTimes.Count, classTimes.Count);
            for (int i = 0; i < txtClassTimes.Count; i++)
            {
                ClassTime parsed =
                    ClassTimeParser.ParseReservedEntry(txtClassTimes[i]);

                Assert.AreEqual(classTimes[i], parsed);
            }
            
        }

        [TestMethod]
        public void ReservedWaitListClassTimeParser()
        {
            List<String> txtClassTimes = new List<String>();
            List<ClassTime> classTimes = new List<ClassTime>();

            txtClassTimes.Add("Jul 5 2010 08:00 - 09:00");
            classTimes.Add(new ClassTime(new DateTime(2010, 7, 5),
                                          new TimeSpan(8, 0, 0), new TimeSpan(9, 0, 0)));

            txtClassTimes.Add("Jul 17 2010 12:30 - 13:30");
            classTimes.Add(new ClassTime(new DateTime(2010, 7, 17),
                                          new TimeSpan(12, 30, 0), new TimeSpan(13, 30, 0)));
            

            Assert.AreEqual(txtClassTimes.Count, classTimes.Count);
            for (int i = 0; i < txtClassTimes.Count; i++)
            {
                ClassTime parsed =
                    ClassTimeParser.ParseBookEntry(txtClassTimes[i]);

                Assert.AreEqual(classTimes[i], parsed);
            }
        }

        [TestMethod]
        public void AvailableClassTimeParser()
        {
        }
    }
}
